// 基本信息
import { Applet } from "@/api/interface/iot";
import DialogBox from "@/components/DialogBox";
import UploadImg from "@/components/Upload/Img.vue";
import { ElForm } from "element-plus";
import { defineComponent, PropType } from "vue";
export default defineComponent({
	props: {
		width: String,
		title: String,
		detail: {
			type: Object as PropType<Applet.ResUserApplet>,
			default() {
				return {};
			}
		}
	},
	emits: ["submit"],
	setup(props, { attrs, emit }) {
		type FormInstance = InstanceType<typeof ElForm>;
		const formRef = ref<FormInstance>();
		const formRule = reactive({
			name: [{ required: true, message: "应用名称不能为空", trigger: "change" }],
			key: [{ required: true, message: "应用标识不能为空", trigger: "change" }]
		});

		watchEffect(() => {});
		onMounted(() => {});

		const validData = () => {
			formRef.value?.validate(async valid => {
				if (valid) {
					emit("submit");
				}
			});
		};
		return () => {
			return (
				<DialogBox {...attrs} width={props.width} title={props.title} onConfirm={() => validData()}>
					<div class="flex">
						<div class="w-52 pr-4">
							<UploadImg
								v-model:imageUrl={props.detail.logo}
								emptyTips="应用图片"
								width="100%"
								height="250px"
								autoUpload
							></UploadImg>
						</div>
						<div class="flex-1">
							<el-form model={props.detail} ref={formRef} rules={formRule} label-width="100px">
								<el-form-item label="应用名称" prop="name">
									<el-input v-model={props.detail.name} placeholder="请输入应用名称" />
								</el-form-item>
								<el-form-item label="应用标识" prop="key">
									<el-input v-model={props.detail.key} placeholder="请输入应用标识" disabled={props.detail.id} />
								</el-form-item>
								<el-form-item label="实际地址" prop="home">
									<el-input v-model={props.detail.home} placeholder="http://127.0.0.1:8080/index.html" />
								</el-form-item>
								<el-form-item label="文档地址" prop="doc">
									<el-input v-model={props.detail.doc} placeholder="http://127.0.0.1:8080/applet/public.pdf" />
								</el-form-item>
								<el-form-item label="描述" prop="desc">
									<el-input v-model={props.detail.desc} placeholder="描述" auto-size type="textarea" rows={8} />
								</el-form-item>
							</el-form>
						</div>
					</div>
				</DialogBox>
			);
		};
	}
});
